#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <fstream>
#include <QDebug>
#include <cstdio>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QMenuBar* menuBar = new QMenuBar();
    setMenuBar(menuBar);
    setWindowTitle("sss menu");

    QMenu* menu1 = new QMenu("file (&F)");
    QMenu* menu2 = new QMenu("edit (&s)");
    QMenu* menu3 = new QMenu("build");
    QMenu* menu4 = new QMenu("Debug");
    QMenu* menu5 = new QMenu("analysiz");
    menuBar->addMenu(menu1);
    menuBar->addMenu(menu2);
    menuBar->addMenu(menu3);
    menuBar->addMenu(menu4);
    menuBar->addMenu(menu5);

    QAction* actionf1 = new QAction("new");
    QAction* actionf2 = new QAction("open");
    QAction* actionf3 = new QAction("reserve");
    QAction* actionf4 = new QAction("delete");
    QAction* actionf5 = new QAction("quit (&Q)");
    menu1->addAction(actionf1);
    menu1->addAction(actionf2);
    menu1->addAction(actionf3);
    menu1->addAction(actionf4);
    menu1->addAction(actionf5);

    connect(actionf1,&QAction::triggered,this,&MainWindow::myclick);
    connect(actionf5,&QAction::triggered,this,&MainWindow::close);

}
void MainWindow::myclick()
{
        FILE* x = fopen("text.txt", "w+");
        if(x == nullptr)
        {
            qDebug()<<"open fail";
            return;
        }
        qDebug() << "open success";
        for(int i = 0; i < 10;i++)
        {
            fputc(i,x);
        }
        fclose(x);
        //fopen(x);
//    std::ofstream file("text.txt");
//    if(!file.is_open())
//    {
//        std::cout << "creat fail" << std::endl;
//        return;
//    }
//    file.close();
//    qDebug() << "creat file";
    //std::ifstream file1("text.txt",std::ios::out);
//    for(int i = 0; i < 10; ++i)
//    {
//        file1 << i;
//    }
        //file1 << "hello word";
}
MainWindow::~MainWindow()
{
    delete ui;
}

